package dataStructure;

import java.util.LinkedList;

public class Stack<T> {
    //LinkedList基于链表并实现了队列
    private final LinkedList<T> list = new LinkedList<>();

    //入栈
    public void push(T data) {
        if (isFull()) throw new RuntimeException("栈已满");
        list.push(data);
    }

    //出栈
    public T pop() {
        if (isEmpty()) throw new RuntimeException("栈为空");
        return list.pop();
    }

    //获取元素个数
    public int size() {
        return list.size();
    }

    //获取栈顶元素
    public T top() {
        if (isEmpty()) throw new RuntimeException("栈为空");
        return list.getFirst();
    }

    //判断是否为空
    public boolean isEmpty() {
        return size() == 0;
    }

    //判断栈是否已满
    public boolean isFull() {
        return size() > 10000;
    }
}
